<?php
/**
 * DESC: 管理员日志
 * 作者:晨光
 * EMAIL:461718846@qq.com
 * DATE:2020/5/11
 */

namespace app\common\model;


use think\facade\Request;
use think\Model;

class AdminLog extends Model
{
    public static function saveLog($operate){
        self::create([
            'admin_id'=>session('admin.id'),
            'ip'=>getIp(),
            'url'=>urldecode(Request::url()),
            'query'=>json_encode(Request::param(),JSON_UNESCAPED_UNICODE),
            'operate'=>$operate,
        ]);
    }

    public static function getList($param){
        $where = [];
        if (!empty($param['keywords'])){
            $where[] = ['operate','like','%'.$param['keywords'].'%'];
        }
        if (!empty($param['create_time'])){
            $time = explode(' - ',$param['create_time']);
            $where[] = ['create_time','between time',$time];
        }
        if (!empty($param['limit'])){
            $data = self::where($where)->order('create_time desc')->paginate($param['limit']);
        }else{
            $data = self::where($where)->order('create_time desc')->select();
        }
        $data = $data->toArray();
        return $data;
    }
}
